#!/usr/bin/env  python
# -*- coding: UTF-8 -*-
import smtplib  
import sys
from email.mime.text import MIMEText  

user = sys.argv[1]  #zabbix传过来的值 
sub = sys.argv[2]
content = sys.argv[3]

def send_mail(username,sub,content):  
    msg = MIMEText(content,_subtype='plain',_charset='gb2312')  
    msg['Subject'] = sub  
    msg['From'] = 'tv-v-no@zabbix.com' #zabbix发送报警邮件 发件人自定义
    msg['To'] = username
    try:  
        server = smtplib.SMTP()  
        server.connect('localhost')  
        server.sendmail('tv-v-no@zabbix.com', username, msg.as_string())  
        server.close()  
    except Exception, e:  
        print str(e)  
        return False  

send_mail(user,sub,content)